<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="模块使用," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="logging 使用">
<meta property="og:type" content="article">
<meta property="og:title" content="(转载)python logging 使用">
<meta property="og:url" content="http://rainy008.github.io/2016/09/21/(转载) python logging 使用/index.html">
<meta property="og:site_name" content="Rainy008">
<meta property="og:description" content="logging 使用">
<meta property="og:updated_time" content="2016-09-26T00:36:24.160Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="(转载)python logging 使用">
<meta name="twitter:description" content="logging 使用">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>

  <title> (转载)python logging 使用 | Rainy008 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">Rainy008</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">重拾梦想  茕茕前行</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                (转载)python logging 使用
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-09-21T10:07:43+08:00" content="2016-09-21">
              2016-09-21
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/Python/" itemprop="url" rel="index">
                    <span itemprop="name">Python</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2016/09/21/(转载) python logging 使用/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2016/09/21/(转载) python logging 使用/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="转载-python-logging-使用"><a href="#转载-python-logging-使用" class="headerlink" title="(转载)python logging 使用"></a>(转载)python logging 使用</h1><p>原文地址： <a href="http://www.cnblogs.com/dkblog/archive/2011/08/26/2155018.html" target="_blank" rel="external">http://www.cnblogs.com/dkblog/archive/2011/08/26/2155018.html</a></p>
<h3 id="ps：还是没看太明白，有时间在详学记录"><a href="#ps：还是没看太明白，有时间在详学记录" class="headerlink" title="ps：还是没看太明白，有时间在详学记录"></a>ps：还是没看太明白，有时间在详学记录</h3><h2 id="1-简单的将日志打印到屏幕"><a href="#1-简单的将日志打印到屏幕" class="headerlink" title="1.简单的将日志打印到屏幕"></a>1.简单的将日志打印到屏幕</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span>  logging</div><div class="line"></div><div class="line">logging . debug ( <span class="string">'This is debug message'</span> )</div><div class="line">logging . info ( <span class="string">'This is info message'</span> )</div><div class="line">logging . warning ( <span class="string">'This is warning message'</span> )</div><div class="line"></div><div class="line"></div><div class="line">屏幕上打印:</div><div class="line"></div><div class="line">WARNING: root: This <span class="keyword">is</span> warning message</div></pre></td></tr></table></figure>
<p>默认情况下，logging将日志打印到屏幕，日志级别为WARNING；<br>日志级别大小关系为：CRITICAL &gt; ERROR &gt; WARNING &gt; INFO &gt; DEBUG &gt; NOTSET，当然也可以自己定义日志级别。 日志级别大小关系为：CRITICAL &gt; ERROR &gt; WARNING &gt; INFO &gt; DEBUG &gt; NOTSET，当然也可以自己定义日志级别:<br><strong>logging.basicConfig(level=logging.DEBUG) ,将日志级别定义为Debug（自加）</strong></p>
<h2 id="2-通过logging-basicConfig函数对日志的输出格式及方式做相关配置"><a href="#2-通过logging-basicConfig函数对日志的输出格式及方式做相关配置" class="headerlink" title="2.通过logging.basicConfig函数对日志的输出格式及方式做相关配置"></a>2.通过logging.basicConfig函数对日志的输出格式及方式做相关配置</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line"></div><div class="line"><span class="keyword">import</span>  logging</div><div class="line"></div><div class="line">logging . basicConfig ( level = logging . DEBUG ,</div><div class="line">                                format = <span class="string">'%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s'</span> ,</div><div class="line">                                datefmt = <span class="string">'%a, %d %b %Y %H:%M:%S'</span> ,</div><div class="line">                                filename = <span class="string">'myapp.log'</span> ,</div><div class="line">                                filemode = <span class="string">'w'</span> )</div><div class="line">       </div><div class="line">logging . debug ( <span class="string">'This is debug message'</span> )</div><div class="line">logging . info ( <span class="string">'This is info message'</span> )</div><div class="line">logging . warning ( <span class="string">'This is warning message'</span> )</div><div class="line"></div><div class="line"> </div><div class="line"></div><div class="line">./myapp.log文件中内容为:</div><div class="line">Sun, <span class="number">24</span> May <span class="number">2009</span> <span class="number">21</span>:<span class="number">48</span>:<span class="number">54</span> demo2.py[line:<span class="number">11</span>] DEBUG This <span class="keyword">is</span> debug message</div><div class="line">Sun, <span class="number">24</span> May <span class="number">2009</span> <span class="number">21</span>:<span class="number">48</span>:<span class="number">54</span> demo2.py[line:<span class="number">12</span>] INFO This <span class="keyword">is</span> info message</div><div class="line">Sun, <span class="number">24</span> May <span class="number">2009</span> <span class="number">21</span>:<span class="number">48</span>:<span class="number">54</span> demo2.py[line:<span class="number">13</span>] WARNING This <span class="keyword">is</span> warning message</div></pre></td></tr></table></figure>
<p>logging.basicConfig函数各参数:<br>filename: 指定日志文件名<br>filemode: 和file函数意义相同，指定日志文件的打开模式，’w’或’a’<br>format: 指定输出的格式和内容，format可以输出很多有用信息，如上例所示:<br>  %(levelno)s: 打印日志级别的数值<br>  %(levelname)s: 打印日志级别名称<br>  %(pathname)s: 打印当前执行程序的路径，其实就是sys.argv[0]<br>  %(filename)s: 打印当前执行程序名<br>  %(funcName)s: 打印日志的当前函数<br>  %(lineno)d: 打印日志的当前行号<br>  %(asctime)s: 打印日志的时间<br>  %(thread)d: 打印线程ID<br>  %(threadName)s: 打印线程名称<br>  %(process)d: 打印进程ID<br>  %(message)s: 打印日志信息<br>datefmt: 指定时间格式，同time.strftime()<br>level: 设置日志级别，默认为logging.WARNING<br>stream: 指定将日志的输出流，可以指定输出到sys.stderr,sys.stdout或者文件，默认输出到sys.stderr，当stream和filename同时指定时，stream被忽略 </p>
<h2 id="3-将日志同时输出到文件和屏幕"><a href="#3-将日志同时输出到文件和屏幕" class="headerlink" title="3.将日志同时输出到文件和屏幕"></a>3.将日志同时输出到文件和屏幕</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span>  logging</div><div class="line"></div><div class="line">logging . basicConfig ( level = logging . DEBUG ,</div><div class="line">                                format = <span class="string">'%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s'</span> ,</div><div class="line">                                datefmt = <span class="string">'%a, %d %b %Y %H:%M:%S'</span> ,</div><div class="line">                                filename = <span class="string">'myapp.log'</span> ,</div><div class="line">                                filemode = <span class="string">'w'</span> )</div><div class="line"></div><div class="line"><span class="comment">#################################################################################################</span></div><div class="line"><span class="comment">#定义一个StreamHandler，将INFO级别或更高的日志信息打印到标准错误，并将其添加到当前的日志处理对象#</span></div><div class="line">console  =  logging . StreamHandler ( )</div><div class="line">console . setLevel ( logging . INFO )</div><div class="line">formatter  =  logging . Formatter ( <span class="string">'%(name)-12s: %(levelname)-8s %(message)s'</span> )</div><div class="line">console . setFormatter ( formatter )</div><div class="line">logging . getLogger ( <span class="string">''</span> ) . addHandler ( console )</div><div class="line"><span class="comment">#################################################################################################</span></div><div class="line"></div><div class="line">logging . debug ( <span class="string">'This is debug message'</span> )</div><div class="line">logging . info ( <span class="string">'This is info message'</span> )</div><div class="line">logging . warning ( <span class="string">'This is warning message'</span> )</div><div class="line"></div><div class="line"> </div><div class="line"></div><div class="line">屏幕上打印:</div><div class="line">root               : INFO         This <span class="keyword">is</span> info message</div><div class="line">root               : WARNING   This <span class="keyword">is</span> warning message</div><div class="line"></div><div class="line">./myapp.log文件中内容为:</div><div class="line">Sun, <span class="number">24</span> May <span class="number">2009</span> <span class="number">21</span>:<span class="number">48</span>:<span class="number">54</span> demo2.py[line:<span class="number">11</span>] DEBUG This <span class="keyword">is</span> debug message</div><div class="line">Sun, <span class="number">24</span> May <span class="number">2009</span> <span class="number">21</span>:<span class="number">48</span>:<span class="number">54</span> demo2.py[line:<span class="number">12</span>] INFO This <span class="keyword">is</span> info message</div><div class="line">Sun, <span class="number">24</span> May <span class="number">2009</span> <span class="number">21</span>:<span class="number">48</span>:<span class="number">54</span> demo2.py[line:<span class="number">13</span>] WARNING This <span class="keyword">is</span> warning message</div></pre></td></tr></table></figure>
<h2 id="4-logging之日志回滚"><a href="#4-logging之日志回滚" class="headerlink" title="4.logging之日志回滚"></a>4.logging之日志回滚</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span>  logging</div><div class="line"><span class="keyword">from</span>  logging . handlers  <span class="keyword">import</span>  RotatingFileHandler</div><div class="line"></div><div class="line"><span class="comment">#################################################################################################</span></div><div class="line"><span class="comment">#定义一个RotatingFileHandler，最多备份5个日志文件，每个日志文件最大10M</span></div><div class="line">Rthandler  =  RotatingFileHandler ( <span class="string">'myapp.log'</span> ,  maxBytes = <span class="number">10</span> * <span class="number">1024</span> * <span class="number">1024</span> , backupCount = <span class="number">5</span> )</div><div class="line">Rthandler . setLevel ( logging . INFO )</div><div class="line">formatter  =  logging . Formatter ( <span class="string">'%(name)-12s: %(levelname)-8s %(message)s'</span> )</div><div class="line">Rthandler . setFormatter ( formatter )</div><div class="line">logging . getLogger ( <span class="string">''</span> ) . addHandler ( Rthandler )</div><div class="line"><span class="comment">################################################################################################</span></div></pre></td></tr></table></figure>
<p>从上例和本例可以看出，logging有一个日志处理的主对象，其它处理方式都是通过addHandler添加进去的。<br>logging的几种handle方式如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">logging.StreamHandler: 日志输出到流，可以是sys.stderr、sys.stdout或者文件</div><div class="line">logging.FileHandler: 日志输出到文件</div><div class="line"></div><div class="line">日志回滚方式，实际使用时用RotatingFileHandler和TimedRotatingFileHandler</div><div class="line">logging.handlers.BaseRotatingHandler</div><div class="line">logging.handlers.RotatingFileHandler</div><div class="line">logging.handlers.TimedRotatingFileHandler</div><div class="line"></div><div class="line">logging.handlers.SocketHandler: 远程输出日志到TCP/IP sockets</div><div class="line">logging.handlers.DatagramHandler:   远程输出日志到UDP sockets</div><div class="line">logging.handlers.SMTPHandler:   远程输出日志到邮件地址</div><div class="line">logging.handlers.SysLogHandler: 日志输出到syslog</div><div class="line">logging.handlers.NTEventLogHandler: 远程输出日志到Windows NT/2000/XP的事件日志</div><div class="line">logging.handlers.MemoryHandler: 日志输出到内存中的制定buffer</div><div class="line">logging.handlers.HTTPHandler: 通过&quot;GET&quot;或&quot;POST&quot;远程输出到HTTP服务器</div></pre></td></tr></table></figure>
<p>由于StreamHandler和FileHandler是常用的日志处理方式，所以直接包含在logging模块中，而其他方式则包含在logging.handlers模块中，<br>上述其它处理方式的使用请参见python2.5手册！</p>
<h2 id="5-通过logging-config模块配置日志"><a href="#5-通过logging-config模块配置日志" class="headerlink" title="5.通过logging.config模块配置日志"></a>5.通过logging.config模块配置日志</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div></pre></td><td class="code"><pre><div class="line">#logger . conf</div><div class="line"></div><div class="line"></div><div class="line">###############################################</div><div class="line"></div><div class="line">[loggers]</div><div class="line">keys=root,example01,example02</div><div class="line"></div><div class="line">[logger_root]</div><div class="line">level=DEBUG</div><div class="line">handlers=hand01,hand02</div><div class="line"></div><div class="line">[logger_example01]</div><div class="line">handlers=hand01,hand02</div><div class="line">qualname=example01</div><div class="line">propagate=0</div><div class="line"></div><div class="line">[logger_example02]</div><div class="line">handlers=hand01,hand03</div><div class="line">qualname=example02</div><div class="line">propagate=0</div><div class="line"></div><div class="line">###############################################</div><div class="line"></div><div class="line">[handlers]</div><div class="line">keys=hand01,hand02,hand03</div><div class="line"></div><div class="line">[handler_hand01]</div><div class="line">class=StreamHandler</div><div class="line">level=INFO</div><div class="line">formatter=form02</div><div class="line">args=(sys.stderr,)</div><div class="line"></div><div class="line">[handler_hand02]</div><div class="line">class=FileHandler</div><div class="line">level=DEBUG</div><div class="line">formatter=form01</div><div class="line">args=(&apos;myapp.log&apos;, &apos;a&apos;)</div><div class="line"></div><div class="line">[handler_hand03]</div><div class="line">class=handlers.RotatingFileHandler</div><div class="line">level=INFO</div><div class="line">formatter=form02</div><div class="line">args=(&apos;myapp.log&apos;, &apos;a&apos;, 10*1024*1024, 5)</div><div class="line"></div><div class="line">###############################################</div><div class="line"></div><div class="line">[formatters]</div><div class="line">keys=form01,form02</div><div class="line"></div><div class="line">[formatter_form01]</div><div class="line">format=%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s</div><div class="line">datefmt=%a, %d %b %Y %H:%M:%S</div><div class="line"></div><div class="line">[formatter_form02]</div><div class="line">format=%(name)-12s: %(levelname)-8s %(message)s</div><div class="line">datefmt=</div></pre></td></tr></table></figure>
<p>上例3：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">import  logging</div><div class="line">import  logging . config</div><div class="line"></div><div class="line">logging . config . fileConfig ( &quot;logger.conf&quot; )</div><div class="line">logger  =  logging . getLogger ( &quot;example01&quot; )</div><div class="line"></div><div class="line">logger . debug ( &apos;This is debug message&apos; )</div><div class="line">logger . info ( &apos;This is info message&apos; )</div><div class="line">logger . warning ( &apos;This is warning message&apos; )</div></pre></td></tr></table></figure></p>
<p>上例4：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">import  logging</div><div class="line">import  logging . config</div><div class="line"></div><div class="line">logging . config . fileConfig ( &quot;logger.conf&quot; )</div><div class="line">logger  =  logging . getLogger ( &quot;example02&quot; )</div><div class="line"></div><div class="line">logger . debug ( &apos;This is debug message&apos; )</div><div class="line">logger . info ( &apos;This is info message&apos; )</div><div class="line">logger . warning ( &apos;This is warning message&apos; )</div></pre></td></tr></table></figure></p>
<h2 id="6-logging是线程安全的"><a href="#6-logging是线程安全的" class="headerlink" title="6.logging是线程安全的"></a>6.logging是线程安全的</h2><p>from: <a href="http://blog.csdn.net/yatere/article/details/6655445" target="_blank" rel="external">http://blog.csdn.net/yatere/article/details/6655445</a></p>

      
    </div>

    <div>
      
        
      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="/path/to/wechat-reward-image" alt="Rainy008 WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="/path/to/alipay-reward-image" alt="Rainy008 Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/模块使用/" rel="tag">#模块使用</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/08/28/(转载）如何拖动文件到python脚本中作为输入参数/" rel="next" title="(转载）如何拖动文件到python脚本中作为输入参数">
                <i class="fa fa-chevron-left"></i> (转载）如何拖动文件到python脚本中作为输入参数
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/09/21/字符编码/" rel="prev" title="字符编码 （Python3 基础教程(廖雪峰) P47）">
                字符编码 （Python3 基础教程(廖雪峰) P47） <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2016/09/21/(转载) python logging 使用/"
           data-title="(转载)python logging 使用" data-url="http://rainy008.github.io/2016/09/21/(转载) python logging 使用/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="Rainy008" />
          <p class="site-author-name" itemprop="name">Rainy008</p>
          <p class="site-description motion-element" itemprop="description">留下记忆足迹，记录所学所想</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">8</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">4</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">5</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#转载-python-logging-使用"><span class="nav-text">(转载)python logging 使用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#ps：还是没看太明白，有时间在详学记录"><span class="nav-text">ps：还是没看太明白，有时间在详学记录</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-简单的将日志打印到屏幕"><span class="nav-text">1.简单的将日志打印到屏幕</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-通过logging-basicConfig函数对日志的输出格式及方式做相关配置"><span class="nav-text">2.通过logging.basicConfig函数对日志的输出格式及方式做相关配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-将日志同时输出到文件和屏幕"><span class="nav-text">3.将日志同时输出到文件和屏幕</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-logging之日志回滚"><span class="nav-text">4.logging之日志回滚</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-通过logging-config模块配置日志"><span class="nav-text">5.通过logging.config模块配置日志</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-logging是线程安全的"><span class="nav-text">6.logging是线程安全的</span></a></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Rainy008</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="http://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"rainy008"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
  





  
  
  

  

  

</body>
</html>
